﻿
#include "FactGroup.h"

FactGroup::FactGroup(QObject *parent)
    : QObject{parent}
{

}
//----------------------------------------------------------------
bool FactGroup::factExists(const QString& name)
{
    if (name.contains(".")) {
        QStringList parts = name.split(".");
        if (parts.count() != 2) {
            return false;
        }
    }
    return factNames_.contains(name);
}
//--------------------------------------------------------------------
Fact *FactGroup::getFact(const QString & name)
{
    if (name.contains(".")) {
        QStringList parts = name.split(".");
        if (parts.count() != 2) {
            return nullptr;
        }
    }
    Fact*   fact = nullptr;
    for(auto i : facts_){
        if(i->name() == name){
            fact = i;
            return fact;
        }
    }
    return fact;
}
//--------------------------------------------------------------------
bool FactGroup::addFact(Fact* fact)
{
    if(fact) {
        if (factNames_.contains(fact->name())) {
            return false;
        }
        factNames_.append(fact->name());
        emit factNamesChanged();
        return true;
    }
    return false;
}
//-------------------------------------------------------------
QStringList  FactGroup::factNames(void)
{
    return this->factNames_;
}
//---------------------------------------------------------------
void FactGroup::resetAllFact()
{
    for(auto i :facts_){
        if(i !=nullptr){
            i->setValue(0);
        }
    }
}


//---------------------------------------------------------------




